﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8" />
    <title>方向条件-按照岗位计算</title>
    <!-- 于庆海 -->
    <link href="../../Comm/Style/Table0.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/bootstrap/js/jquery.min.js" type="text/javascript"></script>
    <script src="../../Scripts/QueryString.js" type="text/javascript"></script>

    <link href="../../Style/skin/css/Default.css" rel="stylesheet" />
    <link href="../../Style/skin/adminfont/iconfont.css" rel="stylesheet" />
    <link href="../../Scripts/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
    <!-- 引用通用的js文件. -->
    <script src="../../Scripts/config.js" type="text/javascript"></script>
    <script src="../../Comm/Gener.js" type="text/javascript"></script>
    <script src="../../Comm/JScript.js" type="text/javascript"></script>
    <script src="../CCFlowEnum.js" type="text/javascript"></script>
    <script src="../Admin.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">
        var selectType = 1;
        //页面启动函数.
        $(function () {

            $("#Msg").html("正在加载,请稍后......");

            InitPage();

            $("#Msg").html("");
        });
        //初始化数据.
        function InitPage() {

            //获取URL参数
            var nodeID = GetQueryString("FK_Node");
            var orgNo = GetQueryString("OrgNo");
            if (orgNo == null || orgNo == undefined)
                orgNo = "";

            var emps = GetQueryString("Stas");
            selectType = GetQueryString("SelectType");
            var CheckStations = emps.split(",");
            //岗位类型集合
            var StationTypes;
            //岗位集合
            var Stations;

            ////根据用户的信息，判断是否启用那个设置工具。
            var user = new WebUser();

            /*调用通用的.*/
            if (orgNo == null || orgNo == "" || orgNo == 0) {
                StationTypes = new Entities("BP.Port.StationTypes");
                StationTypes.RetrieveAll();
                Stations = new Entities("BP.Port.Stations");
                Stations.RetrieveAll();

                /*调用集团模式的.*/
            } else {
                Stations = new Entities("BP.Port.Stations");
                Stations.Retrieve("OrgNo", orgNo);
                //查询出来数据.
               /* var sql = "select No,Name FROM port_StationType WHERE No in (SELECT Fk_StationType from Port_Station WHERE OrgNo ='" + orgNo + "')";
                //获得要增加的流程集合.
                StationTypes = DBAccess.RunSQLReturnTable(sql);*/

                var handler = new HttpHandler("BP.WF.HttpHandler.WF_Admin_Cond2020");
                handler.AddPara("OrgNo", orgNo);
                StationTypes = handler.DoMethodReturnString("SelectStation_StationTypes");
                StationTypes = JSON.parse(StationTypes);
            }
            //初始化岗位Table显示
            InitStationTable(StationTypes, Stations);

            //获取已指定操作员的岗位条件
            for (i = 0, len = CheckStations.length; i < len; i++) {
                if (CheckStations[i] == "")
                    continue;

                var stationObject = document.getElementById("emp_CB_" + CheckStations[i]);
                if (stationObject != null)
                    stationObject.checked = true;
            }
        }

        //初始化岗位列表TABLE
        function InitStationTable(stationTypes, stations) {
            for (var i = 0, len = stationTypes.length; i < len; i++) {
                var typeno = stationTypes[i].No;

                var curstas = [];
                var ids = "";
                for (var j = 0, jlen = stations.length; j < jlen; j++) {
                    if (stations[j].FK_StationType == typeno) {
                        curstas.push(stations[j]);
                        ids += "CB_" + stations[j].No + ",";
                    }
                }

                var title = "<tr><td colspan='3'><label for='CB_type_" + typeno + "' ><input id='CB_type_" + typeno + "' type='checkbox' name='CB_type_" + typeno + "' onclick=\"SetSelected(this.checked,'" + ids + "')\"/>" + stationTypes[i].Name + "</label></td></tr>";
                $("#t1").append(title);

                for (var k = 0, klen = curstas.length; k < klen; k++) {
                    var td = "<td><label for='emp_CB_" + curstas[k].No + "' id=" + curstas[k].No + "><input type='checkbox' id='emp_CB_" + curstas[k].No + "' name='emp_CB_" + curstas[k].No + "'/>" + curstas[k].Name + "</label></td>";
                    if (k % 3 == 0) {
                        $("#t1").append("<tr></tr>");
                    }

                    $("#t1 tr:last").append(td);
                }
            }
        }

        function SetSelected(checked,ids){
            var checkeds = ids.split(',');
            for (var i = 0; i < checkeds.length; i++) {
                var checkid =document.getElementById('emp_'+checkeds[i]);
                checkid.checked = checked;
            }
        }
        
        function Save() {
            var emps = ",";
            var html = "";
            var i = 0;
            var data = new Array();
            $("input[type='checkbox']").each(function () {
                if (this.checked && this.name.indexOf("emp_CB_") == 0) {
                    var id = this.name.replace("emp_CB_", "")
                    emps += id + ",";
                    html += document.getElementById(id).innerText + ",";
                    i++;
                }
            });
            if (html.length != 0)
                html = html.substring(0, html.length - 1);
            data[0] = emps;
            data[1] = html;
            data[2] = i;
            data[3] = selectType;

            window.parent.window.getChidrenValue(data);

        }
    </script>

    <style type="text/css">
        ul .cond li {
            display: none;
            line-height: 50px;
        }

            ul .cond li .active {
                display: block;
            }

        select {
            display: inline-block;
            width: 200px;
        }

        .btn {
            display: inline-block;
            height: 20px;
            background-color: #0099ff;
            text-decoration: none;
            color: #fff;
            padding: 3px 15px;
            margin: 10px 10px;
        }

        .lbls span {
            width: 80px;
        }
    </style>
</head>
<body>
    <div style="margin-bottom:10px;">
        <button value='保存' onclick='Save();' class="cc-btn-tab btn-save" id='Save'>保存</button>
        <button onclick="Back()" value="返回" class="cc-btn-tab btn-back" id="Button2">返回</button>
    </div>
    <div id="tableDiv" style="max-height:600px;overflow:auto;min-height:330px">
        <table id="t1" class="table">
        </table>
    </div>
    <div id="Msg"></div>
</body>
</html>
